export default {
	data (){
		return {
			// value4: '',//搜索框
            loading: false,//表单懒加载
        	formValidate: {//表单
                title: '',
                author: '',
                otherTitle: '',
                date: '',
                style:[],
                tips:[],
                imgUrl:'',
                id: '',//表单的隐藏域用于储存id
            },
            imageTableData: [//动态获取请求到的数据
            ],
            pageData: {
                total:20,
                limit: 10,
                page: 1,
                pages: 2,
                name:''
            },
            select: [],
            selecturl: []

		}
	},
	methods: {
		reload (item,) {//得到数据对页面的重新载入
	       this.$http({
                method:"POST",
                url:`http://localhost:3000/${ this.module }/list`,
                data:this.pageData
            })
	        .then((response) => {
                console.log(response)
	            this.imageTableData = response.data.rows;
	            this.pageData.total = response.data.total;
	        })
	        .catch((response) => {});
	    },
        remove (index,id,filename) {//删除与批量删除
            if (this.select.length) {
                this.$Message.warning('请选择批量删除');
                return;
            }else{
                this.imageTableData.splice(index, 1);
                this.$http({
                    method:"DELETE",
                    url:`http://localhost:3000/${ this.module }/data`+id,
                })
                .then((response) => {
                    console.log('成功')
                    this.reload();
                })
                .catch((response) => {
                    console.log("失败"+response)
                });
                //对图片文件的删除
                this.$http({
                    method:"POST",
                    url:`http://localhost:3000/${ this.module }/delete`,
                    data:{
                        url:filename
                    }
                })
                .then((response) => {
                })
                .catch((response) => {
                });
            }
        },
        allremove(index,id) {//批量删除
            if(!this.select.length) {
                this.$Message.warning('请选择删除的条目');
                return;
            }else{
                this.isRemoveModal = true;
            }
        },
        okremove() {
            this.okremove_loading = true;//loding加载环
            setTimeout(() => {
                this.okremove_loading = true;
                var idBox = [];
                for (var i = 0; i < this.select.length; i++) {
                    idBox.push(this.select[i]._id);
                }
                console.log(idBox);
                this.$http({
                    method:"DELETE",
                    url:`http://localhost:3000/${ this.module }/data`+idBox,
                })
                .then((response) => {
                    this.isRemoveModal = false; 
                    this.$Message.success('删除成功');           
                    this.okremove_loading = false;
                    this.select = [];//删除成功后将checkbox中的
                    this.reload();
                })
                .catch((response) => {
                    this.isRemoveModal = false; 
                    this.$Message.warning('服务器异常');
                    this.okremove_loading = false;
                    console.log(response)
                });
            },2000)
        },

            // else {
            //         console.log('多个删除')
            //         for(var i=0;i<this.select.length;i++) {
            //             this.selecturl.push(this.select[i].filename)
            //         }
            //         console.log(this.selecturl)
            //         this.warning();
            //         var idBox = [];
            //         for (var i = 0; i < this.select.length; i++) {
            //             idBox.push(this.select[i]._id);
            //         }
            //         this.$http({
            //             method:"DELETE",
            //             url:`http://localhost:3000/${ this.module }/data`+idBox,
            //         })
            //         .then((response) => {
            //             this.reload();
            //         })
            //         .catch((response) => {
            //             console.log(response)
            //         });
    
            //         this.$http({
            //             method:"POST",
            //             url:`http://localhost:3000/${ this.module }/delete`,
            //             data:this.selecturl
            //         })
            //         .then((response) => {
            //             console.log('删除图片成功后删除')
            //         })
            //         .catch((response) => {
            //         });
            //         this.selecturl = ['']
            //         this.select = null
            // }

        search () {//搜索
       		this.reload();
        },
        changePage(page){//分页方法
            this.loading = true;
            var that = this;
            var tableTimer = setTimeout(function() {
                that.loading = false;
            }, 600);

            this.$http({
                method:'POST',
                url:`http://localhost:3000/${ this.module }/list`,
                data:{
                    page:page,
                }
            }).then((response)=>{
                this.imageTableData = response.data.rows;
            })
        },
        changePageSize(limit) {//一页最大数据数码
            this.loading = true;
            var that = this;
            var tableTimer = setTimeout(function() {
                that.loading = false
            }, 600);
            this.$http({
                method:'POST',
                url:`http://localhost:3000/${ this.module }/list`,
                data:{
                    rows:limit
                }
            }).then((response)=>{
                this.imageTableData = response.data.rows;
            })
        },
	},
	created: function() {//钩子函数创建
        this.reload();
    },

}